package com.bookmanager.www.controller.rabbitmq;

import com.bookmanager.www.common.utils.EmailUtils;
import com.bookmanager.www.common.utils.PhoneCodeUtils;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

/**
 * Created with IntelliJ IDEA.
 *
 * @author: 风离
 * @Date: 2021/10/14/22:01
 * @Description:
 */
@Component
public class EmailReceiver {

    @RabbitListener(bindings = {
            @QueueBinding(
                            value = @Queue,
                            exchange = @Exchange(name = "sendEmail", type = "fanout")
                    )
            })
    public void emailReceiver(String message)
    {
        String[] strings = message.split(" ");
        String email = strings[0];
        String password =strings[1];
        System.out.println("通知邮箱是否发送成功？？"+EmailUtils.sendMessageToUser(email,password));
    }

    @RabbitListener(queuesToDeclare =@Queue(name="sendPhoneCode"))
    public void phoneCodeReceiver(String message)
    {
        String[] strings = message.split(" ");
        String phoneNumber = strings[0];
        String password =strings[1];
        System.out.println("通知短信是否发送成功？？"+ PhoneCodeUtils.sendMessageCode(phoneNumber,password));
    }



}
